package org.takeback.chat.service.admin;

import com.google.common.collect.ImmutableMap;
import java.util.Calendar;
import java.util.Date;
import java.util.Map;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.takeback.chat.utils.DateUtil;
import org.takeback.core.service.MyListServiceInt;
import org.takeback.dao.BaseDAO;

@Service("redDetailService")
public class RedDetailService extends MyListServiceInt {
	@Transactional(rollbackFor = { Throwable.class })
	public void clear(Map<String, Object> req) {
		this.dao.executeUpdate("delete from GcLottery", ImmutableMap.of());
		this.dao.executeUpdate("delete from GcLotteryDetail", ImmutableMap.of());
	}

	@Transactional(rollbackFor = { Throwable.class })
	public void clear2(Map<String, Object> req) {
		Calendar c = Calendar.getInstance();
		c.setTime(DateUtil.getStartOfToday());
		c.add(5, -2);
		Date d = c.getTime();
		this.dao.executeUpdate("delete from GcLottery where createTime <=:time", ImmutableMap.of("time", c.getTime()));
		this.dao.executeUpdate("delete from GcLotteryDetail where createDate<=:time",
				ImmutableMap.of("time", c.getTime()));
	}

	@Transactional(rollbackFor = { Throwable.class })
	public void clear5(Map<String, Object> req) {
		Calendar c = Calendar.getInstance();
		c.setTime(DateUtil.getStartOfToday());
		c.add(5, -5);
		this.dao.executeUpdate("delete from GcLottery where createTime <=:time", ImmutableMap.of("time", c.getTime()));
		this.dao.executeUpdate("delete from GcLotteryDetail where createDate<=:time",
				ImmutableMap.of("time", c.getTime()));
	}
}
